package cn.tedu.flowers.mapper;


import cn.tedu.flowers.entity.Product;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProductMapper {

    @Insert("insert into product values(null,#{title},#{name},#{price},#{intro},#{categoryId},#{url})")
    void insert(Product product);

    //当查询的表里面的字段名和实体类中的属性名不一致时,
    //需要通过@Result注解写一个对应关系,不然数据会查询不到
    @Select("select * from product")
    List<Product> select();

    @Delete("delete from product where id=#{id}")
    void delete(int id);

    @Select("select id,title,name,url from product where categoryId=#{cid}")
    List<Product> selectByCid(int cid);


    @Select("select id,title ,url from product where title like concat('%',#{wd},'%') ")
    List<Product> selectByWd(String wd);

}
